package org.dromara.business.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.business.domain.vo.VolunteerDetailsVo;
import org.dromara.business.domain.bo.VolunteerDetailsBo;
import org.dromara.business.service.VolunteerDetailsService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 志愿者详细信息
 *
 * @author zlj
 * @date 2025-01-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/volunteer")
public class VolunteerDetailsController extends BaseController {

    private final VolunteerDetailsService volunteerDetailsService;

    /**
     * 查询志愿者详细信息列表
     */
//    @SaCheckPermission("business:volunteer:list")
    @GetMapping("/list")
    public TableDataInfo<VolunteerDetailsVo> list(VolunteerDetailsBo bo, PageQuery pageQuery) {
        return volunteerDetailsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出志愿者详细信息列表
     */
//    @SaCheckPermission("business:volunteer:export")
    @Log(title = "志愿者详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(VolunteerDetailsBo bo, HttpServletResponse response) {
        List<VolunteerDetailsVo> list = volunteerDetailsService.queryList(bo);
        ExcelUtil.exportExcel(list, "志愿者详细信息", VolunteerDetailsVo.class, response);
    }

    /**
     * 获取志愿者详细信息详细信息
     *
     * @param userId 主键
     */
//    @SaCheckPermission("business:volunteer:query")
    @GetMapping("/{userId}")
    public R<VolunteerDetailsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long userId) {
        return R.ok(volunteerDetailsService.queryById(userId));
    }

    /**
     * 新增志愿者详细信息
     */
//    @SaCheckPermission("business:volunteer:add")
    @Log(title = "志愿者详细信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody VolunteerDetailsBo bo) {
        return toAjax(volunteerDetailsService.insertByBo(bo));
    }

    /**
     * 修改志愿者详细信息
     */
//    @SaCheckPermission("business:volunteer:edit")
    @Log(title = "志愿者详细信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody VolunteerDetailsBo bo) {
        return toAjax(volunteerDetailsService.updateByBo(bo));
    }

    /**
     * 删除志愿者详细信息
     *
     * @param userIds 主键串
     */
//    @SaCheckPermission("business:volunteer:remove")
    @Log(title = "志愿者详细信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] userIds) {
        return toAjax(volunteerDetailsService.deleteWithValidByIds(List.of(userIds), true));
    }
}
